import * as Notifications from 'expo-notifications';

// 配置通知处理行为
Notifications.setNotificationHandler({
  handleNotification: async () => ({
    shouldShowAlert: true,
    shouldPlaySound: true,
    shouldSetBadge: true,
  }),
});

// 请求通知权限
export async function requestNotificationPermission() {
  const { status } = await Notifications.requestPermissionsAsync();
  return status === 'granted';
}

// 创建通知渠道（Android）
export async function configureNotificationChannel() {
  await Notifications.setNotificationChannelAsync('default', {
    name: 'Default',
    importance: Notifications.AndroidImportance.HIGH,
    vibrationPattern: [0, 250, 250, 250],
    lightColor: '#FF231F7C',
  });
}

// 发送带图片的本地通知
export async function scheduleLocalNotification() {
  await Notifications.scheduleNotificationAsync({
    content: {
      title: '消息 📬',
      body: '全球资产RWA交易所欢迎您',
      data: { screen: 'Messages' }, // 自定义数据
      // 本地图片配置（需要配置assetBundlePatterns）
      attachments: [{
        url: require('@/assets/images/logo.png')
      }]
    },
    trigger: { seconds: 2 }, // 立即触发
  });
}